import subprocess
import subprocess
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from drf_spectacular.utils import extend_schema, OpenApiParameter
from rest_framework.response import Response


@extend_schema(tags = ["检查设备连通性"])
@api_view(['GET'])
def PingHost(request, ip_address):
    try:
        output = subprocess.check_output(["ping", "-c", "1", ip_address])
        return Response({"reachable": True}, status=status.HTTP_200_OK)
    except subprocess.CalledProcessError:
        return Response({"reachable": False}, status=status.HTTP_200_OK)